package wntransform.gui;

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.SwingWorker;
import org.xml.sax.SAXException;
import wntransform.transformation.CZToPLTransformation;
import wntransform.transformation.PLToCZTransformation;
import wntransform.validation.WNTransformValidation;
import wntransform.transformation.Transformation;

public class WNTransformGUIView extends FrameView {

    private String CZ_WORDNET_SCHEMA = "czWordnetValidator.xsd";//WNTransformGUIView.class.getResource("resources/czWordnetValidator.xsd").getPath();
    private final String PL_WORDNET_SCHEMA = "plWordnetValidator.xsd";//WNTransformGUIView.class.getResource("resources/plWordnetValidator.xsd").getPath();
    private final String CZ_XSL = "CzPlFormatOutput.xsl";//WNTransformGUIView.class.getResource("resources/CzPlFormatOutput.xsl").getPath();
    private final String PL_XSL = "PlCzFormatOutput.xsl";//WNTransformGUIView.class.getResource("resources/PlCzFormatOutput.xsl").getPath();
    private final String INITIAL_INPUT_TEXT = "Type here name of input XML or click on Browse";
    private final String PLS_VALIDATE = "Please validate the file!";
    private SwingWorkerCZToPLTran czToPLTran = null;
    private SwingWorkerPLToCZTran plToCZTran = null;
    private SwingWorkerCZToPLVal czToPLVal = null;
    private SwingWorkerPLToCzVal plToCZVal = null;
    private final String TEMP_WELL_FORMED = "wellFormedCZFile.xml";

    @Override
    public ResourceMap getResourceMap() {
        return super.getResourceMap();
    }

    private class SwingWorkerCZToPLTran extends SwingWorker<Integer, Integer> {

        StringBuilder outputFile = null;
        String tempWellFormedFile = null;

        protected Integer doInBackground() throws Exception {

            int result = 0;

            String inputFile = inputXMLTextField.getText();
            outputFile = new StringBuilder(inputFile);
            tempWellFormedFile = TEMP_WELL_FORMED;

            Transformation transformation = new CZToPLTransformation();

            outputFile.replace(inputFile.length() - 4, inputFile.length(), "TransformedToPL.xml");
            inputFile = tempWellFormedFile;

            try {
                transformation.transformXML(inputFile, outputFile.toString(), CZ_XSL);
                File outputFileTemp = new File(TEMP_WELL_FORMED);
                outputFileTemp.delete();
            } catch (Exception ex) {
                handleTransformationErrors(ex);
                cancel(true);
            }

            return result;
        }

        protected void done() {

            progressBar.setIndeterminate(false);

            if (!isCancelled()) {
                infoThatTransformationCompletedSuccessfully(outputFile.toString());
                File outputFileTemp = new File(TEMP_WELL_FORMED);
                outputFileTemp.delete();
            }

            czToPLTran = null;
        }
    }

    private class SwingWorkerPLToCZTran extends SwingWorker<Integer, Integer> {

        StringBuilder outputFile = null;

        protected Integer doInBackground() throws Exception {

            int result = 0;

            String inputFile = inputXMLTextField.getText();
            outputFile = new StringBuilder(inputFile);
            outputFile.replace(inputFile.length() - 4, inputFile.length(), "TransformedToCZ.xml");

            Transformation transformation = new PLToCZTransformation();

            try {
                transformation.transformXML(inputFile, outputFile.toString(), PL_XSL);
            } catch (Exception ex) {
                handleTransformationErrors(ex);
                cancel(true);
            }

            return result;
        }

        protected void done() {

            progressBar.setIndeterminate(false);
            if (!isCancelled()) {
                infoThatTransformationCompletedSuccessfully(outputFile.toString());
            }
            plToCZTran = null;
        }
    }

    private class SwingWorkerCZToPLVal extends SwingWorker<Integer, Integer> {

        protected Integer doInBackground() throws Exception {

            int result = 0;

            WNTransformValidation validation = new WNTransformValidation();

            try {
                validation.validateCZ(inputXMLTextField.getText(), CZ_WORDNET_SCHEMA);
            } catch (SAXException ex) {
                saxExceptionInfo(ex);
                cancel(true);
            } catch (Exception ex) {
                otherExceptionInfo();
                cancel(true);
            }

            return result;
        }

        protected void done() {

            progressBar.setIndeterminate(false);

            if (!isCancelled()) {
                informThatValidationCompletedSuccessfully();
            }

            czToPLVal = null;
        }
    }

    private class SwingWorkerPLToCzVal extends SwingWorker<Integer, Integer> {

        protected Integer doInBackground() throws Exception {

            int result = 0;

            WNTransformValidation validation = new WNTransformValidation();

            try {
                validation.validatePL(inputXMLTextField.getText(), PL_WORDNET_SCHEMA);
                progressBar.setIndeterminate(false);
            } catch (SAXException ex) {
                saxExceptionInfo(ex);
                cancel(true);
            } catch (Exception ex) {
                otherExceptionInfo();
                cancel(true);
            }

            return result;
        }

        protected void done() {

            progressBar.setIndeterminate(false);

            if (!isCancelled()) {
                informThatValidationCompletedSuccessfully();
            }

            plToCZVal = null;
        }
    }

    private void handleTransformationErrors(Exception ex) {

        cancelButton.setEnabled(false);
        transformButton.setEnabled(false);
        messagesEditorPane.setForeground(Color.red);
        File errorLog = new File("error.log");
        PrintStream pstr = null;

        File outputFileTemp = new File(TEMP_WELL_FORMED);
        if (outputFileTemp.exists()) {
            outputFileTemp.delete();
        }

        try {
            errorLog.createNewFile();
            pstr = new PrintStream(errorLog);

            ex.printStackTrace(pstr);

            pstr.flush();
        } catch (IOException ioEx) {

            messagesEditorPane.setText("An error during logging of transforming error occured!\n"
                    + "Please rerun the transformation again!");

        } finally {

            pstr.close();
        }

        messagesEditorPane.setText("An error during transformation occured!\n"
                + "Check the error.log for more informations!");
    }

    private void infoThatTransformationCompletedSuccessfully(String outputFile) {

        cancelButton.setEnabled(false);
        messagesEditorPane.setForeground(Color.blue);
        messagesEditorPane.setText("Transformation completed successfully!\n "
                + "The result was written into new file which can be found in:\n"
                + outputFile);
    }

    private void infoThatOperationTakeAWhile() {
        messagesEditorPane.setForeground(Color.black);
        messagesEditorPane.setText("This operation may take a while!\n"
                + "Please be patient!");
    }

    public WNTransformGUIView(SingleFrameApplication app) {
        super(app);
        initComponents();
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = WNTransformGUIApp.getApplication().getMainFrame();
            aboutBox = new WNTransformGUIAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        WNTransformGUIApp.getApplication().show(aboutBox);
    }

    private String getResourcePath(String resource) {

        String rawPath = WNTransformGUIView.class.getResource("WNTransformGUIView.class").getPath();

        rawPath = rawPath.replace("!", "");

        rawPath = rawPath.substring(0, rawPath.lastIndexOf("/") + 1);

        return rawPath + "src/wntransform/gui/resources/" + resource;
    }

    @Action
    public void cancelOperation() {

        messagesEditorPane.setForeground(Color.black);
        String message = "Operation canceled!";

        File outputFileTemp = new File(TEMP_WELL_FORMED);

        if (czToPLTran != null) {
            czToPLTran.cancel(true);

            messagesEditorPane.setText(message);
            cancelButton.setEnabled(false);
            transformButton.setEnabled(true);
            validateButton.setEnabled(false);
        }

        if (plToCZTran != null) {
            plToCZTran.cancel(true);

            messagesEditorPane.setText(message);
            cancelButton.setEnabled(false);
            transformButton.setEnabled(true);
            validateButton.setEnabled(false);
        }

        if (czToPLVal != null) {
            czToPLVal.cancel(true);

            messagesEditorPane.setText(message);
            cancelButton.setEnabled(false);
            transformButton.setEnabled(false);
            validateButton.setEnabled(true);

            if (outputFileTemp.exists()) {
                outputFileTemp.delete();
            }
        }

        if (plToCZVal != null) {
            plToCZVal.cancel(true);

            messagesEditorPane.setText(message);
            cancelButton.setEnabled(false);
            transformButton.setEnabled(false);
            validateButton.setEnabled(true);

            if (outputFileTemp.exists()) {
                outputFileTemp.delete();
            }
        }
    }

    @Action
    public void showFileChooser() {

        if (fileChooser == null) {
            JFrame mainFrame = WNTransformGUIApp.getApplication().getMainFrame();
            fileChooser = new JFileChooser();

        }

        validateButton.setEnabled(true);
        transformButton.setEnabled(false);
        messagesEditorPane.setForeground(Color.black);
        messagesEditorPane.setText(PLS_VALIDATE);

        int returnVal = fileChooser.showOpenDialog(transformationsTab);

        if (returnVal == JFileChooser.APPROVE_OPTION) {

            File file = fileChooser.getSelectedFile();
            inputXMLTextField.setText(file.getAbsolutePath());
        }

    }

    @Action
    public void transformXML() {

        messagesEditorPane.setText("");
        transformButton.setEnabled(false);
        validateButton.setEnabled(false);
        cancelButton.setEnabled(true);

        String typeOfTransformation = typeOfTransComboBox.getSelectedItem().toString();

        boolean result = false;

        if (typeOfTransformation.equals("CZ to PL")) {

            infoThatOperationTakeAWhile();
            czToPLTran = new SwingWorkerCZToPLTran();
            progressBar.setIndeterminate(true);
            czToPLTran.execute();

        } else if (typeOfTransformation.equals("PL to CZ")) {

            infoThatOperationTakeAWhile();
            plToCZTran = new SwingWorkerPLToCZTran();
            progressBar.setIndeterminate(true);
            plToCZTran.execute();

        }
    }

    @Action
    public void validateXML() {

        transformButton.setEnabled(false);
        validateButton.setEnabled(false);
        cancelButton.setEnabled(true);
        messagesEditorPane.setText("");


        String checkInputFile = inputXMLTextField.getText();

        if (checkInputFile.trim().equals("")) {

            informAboutBadInputFileName();
            return;

        } else if (checkInputFile.trim().equals(INITIAL_INPUT_TEXT)) {

            informAboutBadInputFileName();
            return;

        } else if (!(checkInputFile.trim()).endsWith(".xml")) {

            informAboutBadInputFileName();
            return;
        }

        final WNTransformValidation validation = new WNTransformValidation();

        String typeOfTransformation = typeOfTransComboBox.getSelectedItem().toString();

        if (typeOfTransformation.equals("CZ to PL")) {

            infoThatOperationTakeAWhile();
            czToPLVal = new SwingWorkerCZToPLVal();
            progressBar.setIndeterminate(true);
            czToPLVal.execute();

        } else if (typeOfTransformation.equals("PL to CZ")) {

            infoThatOperationTakeAWhile();
            plToCZVal = new SwingWorkerPLToCzVal();
            progressBar.setIndeterminate(true);
            plToCZVal.execute();

        }
    }

    private void informAboutBadInputFileName() {

        String errorMessageSpecified = "The input file has to be specified correctly!";

        messagesEditorPane.setForeground(Color.red);
        messagesEditorPane.setText(errorMessageSpecified);
        cancelButton.setEnabled(false);
        validateButton.setEnabled(true);
    }

    private void saxExceptionInfo(SAXException ex) {

        File outputFileTemp = new File(TEMP_WELL_FORMED);
        if (outputFileTemp.exists()) {
            outputFileTemp.delete();
        }
        messagesEditorPane.setForeground(Color.red);
        messagesEditorPane.setText("Given document is not valid XML according to Wordnet XML schema!\n"
                + "Check the type of chosen transformation!\n"
                + "Reason: " + ex.getMessage());
    }

    private void otherExceptionInfo() {

        File outputFileTemp = new File(TEMP_WELL_FORMED);
        if (outputFileTemp.exists()) {
            outputFileTemp.delete();
        }
        messagesEditorPane.setForeground(Color.red);
        messagesEditorPane.setText("Error occured while file was validated, please try it again!");
    }

    private void informThatValidationCompletedSuccessfully() {
        cancelButton.setEnabled(false);
        messagesEditorPane.setForeground(Color.blue);
        messagesEditorPane.setText("Given document is valid XML according to Wordnet xml schema!");
        transformButton.setEnabled(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        AllTabs = new javax.swing.JTabbedPane();
        transformationsTab = new javax.swing.JPanel();
        browseButton = new javax.swing.JButton();
        inputXMLTextField = new javax.swing.JTextField();
        typeOfTransComboBox = new javax.swing.JComboBox();
        chooseTypeLabel = new javax.swing.JLabel();
        validateButton = new javax.swing.JButton();
        transformButton = new javax.swing.JButton();
        messagesScrollPane = new javax.swing.JScrollPane();
        messagesEditorPane = new javax.swing.JEditorPane();
        progressBar = new javax.swing.JProgressBar();
        cancelButton = new javax.swing.JButton();
        AuthorsTab = new javax.swing.JPanel();
        authorsLabel = new javax.swing.JLabel();
        jakubLabel = new javax.swing.JLabel();
        juroLabel = new javax.swing.JLabel();
        paloLabel = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        fileChooser = new javax.swing.JFileChooser();

        mainPanel.setMaximumSize(new java.awt.Dimension(800, 600));
        mainPanel.setMinimumSize(new java.awt.Dimension(400, 300));
        mainPanel.setName("mainPanel"); // NOI18N

        AllTabs.setName("AllTabs"); // NOI18N

        transformationsTab.setName("transformationsTab"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(wntransform.gui.WNTransformGUIApp.class).getContext().getActionMap(WNTransformGUIView.class, this);
        browseButton.setAction(actionMap.get("showFileChooser")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(wntransform.gui.WNTransformGUIApp.class).getContext().getResourceMap(WNTransformGUIView.class);
        browseButton.setText(resourceMap.getString("browseButton.text")); // NOI18N
        browseButton.setName("browseButton"); // NOI18N

        inputXMLTextField.setText(INITIAL_INPUT_TEXT);
        inputXMLTextField.setName("inputXMLTextField"); // NOI18N
        inputXMLTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                inputChangedHandler(evt);
            }
        });

        typeOfTransComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CZ to PL", "PL to CZ" }));
        typeOfTransComboBox.setName("typeOfTransComboBox"); // NOI18N
        typeOfTransComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboxBoxChangedHandler(evt);
            }
        });

        chooseTypeLabel.setText(resourceMap.getString("chooseTypeLabel.text")); // NOI18N
        chooseTypeLabel.setName("chooseTypeLabel"); // NOI18N

        validateButton.setAction(actionMap.get("validateXML")); // NOI18N
        validateButton.setText(resourceMap.getString("validateButton.text")); // NOI18N
        validateButton.setName("validateButton"); // NOI18N

        transformButton.setAction(actionMap.get("transformXML")); // NOI18N
        transformButton.setText(resourceMap.getString("transformButton.text")); // NOI18N
        transformButton.setName("transformButton"); // NOI18N
        transformButton.setEnabled(false);

        messagesScrollPane.setName("messagesScrollPane"); // NOI18N

        messagesEditorPane.setEditable(false);
        messagesEditorPane.setName("messagesEditorPane"); // NOI18N
        messagesScrollPane.setViewportView(messagesEditorPane);

        progressBar.setName("progressBar"); // NOI18N

        cancelButton.setAction(actionMap.get("cancelOperation")); // NOI18N
        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setEnabled(false);
        cancelButton.setName("cancelButton"); // NOI18N

        javax.swing.GroupLayout transformationsTabLayout = new javax.swing.GroupLayout(transformationsTab);
        transformationsTab.setLayout(transformationsTabLayout);
        transformationsTabLayout.setHorizontalGroup(
            transformationsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transformationsTabLayout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(transformationsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(transformationsTabLayout.createSequentialGroup()
                        .addComponent(messagesScrollPane)
                        .addContainerGap())
                    .addGroup(transformationsTabLayout.createSequentialGroup()
                        .addGroup(transformationsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(transformationsTabLayout.createSequentialGroup()
                                .addComponent(chooseTypeLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(typeOfTransComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(transformationsTabLayout.createSequentialGroup()
                                .addComponent(inputXMLTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 517, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(browseButton)))
                        .addGap(28, 28, 28))
                    .addGroup(transformationsTabLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(validateButton)
                        .addGap(18, 18, 18)
                        .addComponent(transformButton, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        transformationsTabLayout.setVerticalGroup(
            transformationsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transformationsTabLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(transformationsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inputXMLTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browseButton))
                .addGap(51, 51, 51)
                .addGroup(transformationsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(chooseTypeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(typeOfTransComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(messagesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(transformationsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(validateButton)
                    .addComponent(transformButton)
                    .addComponent(cancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        AllTabs.addTab(resourceMap.getString("transformationsTab.TabConstraints.tabTitle"), transformationsTab); // NOI18N

        AuthorsTab.setName("AuthorsTab"); // NOI18N

        authorsLabel.setText(resourceMap.getString("authorsLabel.text")); // NOI18N
        authorsLabel.setName("authorsLabel"); // NOI18N

        jakubLabel.setText(resourceMap.getString("jakubLabel.text")); // NOI18N
        jakubLabel.setName("jakubLabel"); // NOI18N

        juroLabel.setText(resourceMap.getString("juroLabel.text")); // NOI18N
        juroLabel.setName("juroLabel"); // NOI18N

        paloLabel.setText(resourceMap.getString("paloLabel.text")); // NOI18N
        paloLabel.setName("paloLabel"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout AuthorsTabLayout = new javax.swing.GroupLayout(AuthorsTab);
        AuthorsTab.setLayout(AuthorsTabLayout);
        AuthorsTabLayout.setHorizontalGroup(
            AuthorsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AuthorsTabLayout.createSequentialGroup()
                .addGroup(AuthorsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AuthorsTabLayout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(authorsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(AuthorsTabLayout.createSequentialGroup()
                        .addGap(160, 160, 160)
                        .addGroup(AuthorsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(juroLabel)
                            .addComponent(paloLabel)
                            .addComponent(jakubLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(126, Short.MAX_VALUE))
        );
        AuthorsTabLayout.setVerticalGroup(
            AuthorsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AuthorsTabLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(authorsLabel)
                .addGap(18, 18, 18)
                .addComponent(jakubLabel)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(juroLabel)
                .addGap(18, 18, 18)
                .addComponent(paloLabel)
                .addContainerGap(136, Short.MAX_VALUE))
        );

        AllTabs.addTab(resourceMap.getString("AuthorsTab.TabConstraints.tabTitle"), AuthorsTab); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(AllTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(AllTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
                .addGap(21, 21, 21))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        fileChooser.setName("fileChooser"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void inputChangedHandler(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inputChangedHandler
        transformButton.setEnabled(false);
        validateButton.setEnabled(true);
        messagesEditorPane.setForeground(Color.black);
        messagesEditorPane.setText(PLS_VALIDATE);
    }//GEN-LAST:event_inputChangedHandler

    private void comboxBoxChangedHandler(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboxBoxChangedHandler
        transformButton.setEnabled(false);
        validateButton.setEnabled(true);
        messagesEditorPane.setForeground(Color.black);
        messagesEditorPane.setText(PLS_VALIDATE);
    }//GEN-LAST:event_comboxBoxChangedHandler
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane AllTabs;
    private javax.swing.JPanel AuthorsTab;
    private javax.swing.JLabel authorsLabel;
    private javax.swing.JButton browseButton;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel chooseTypeLabel;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JTextField inputXMLTextField;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jakubLabel;
    private javax.swing.JLabel juroLabel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JEditorPane messagesEditorPane;
    private javax.swing.JScrollPane messagesScrollPane;
    private javax.swing.JLabel paloLabel;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JButton transformButton;
    private javax.swing.JPanel transformationsTab;
    private javax.swing.JComboBox typeOfTransComboBox;
    private javax.swing.JButton validateButton;
    // End of variables declaration//GEN-END:variables
    private int busyIconIndex = 0;
    private JDialog aboutBox;
}
